﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using PoznanEvents.Helpers;
using PoznanEvents.ViewModels;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Controls.Maps;
using System.Device.Location;

namespace PoznanEvents
{
    public partial class EventPage1 : PhoneApplicationPage
    {
        public EventPage1()
        {
            InitializeComponent();
            DataContext = App.ViewModel.SelectedEvent;
            EventMap.CredentialsProvider = new ApplicationIdCredentialsProvider("AsNqgjle8C4_dyrcgfaqiIO1Cggmf6bLLvThv0sIDx6HJ8X59gEJiT0W8XR5Mbg1");
        }

        private void EventVersionHtml_Loaded(object sender, RoutedEventArgs e)
        {
            var html = "<html><body>";
            html += App.ViewModel.SelectedEvent.EventVersion;
            html = html + "</body></html>";
            EventVersionHtml.NavigateToString(StringHelper.FixHtml(html));

        }

        private void EventPageBarIconButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(App.ViewModel.SelectedEvent.EventUrl))
            {
                MessageBox.Show("Wydarzenie nie posiada dodatkowej zawartości");
            }
            else
            {
                WebBrowserTask webBroswerTask = new WebBrowserTask();
                webBroswerTask.Uri = new Uri(App.ViewModel.SelectedEvent.EventUrl);
                webBroswerTask.Show();
            }
        }

        private void GoBackBarIconButton_Click(object sender, EventArgs e)
        {
            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
        }

        private void EventMap_Loaded(object sender, RoutedEventArgs e)
        {
            Pushpin pin = new Pushpin();
            pin.Background = new SolidColorBrush(Colors.Yellow);
            pin.Foreground = new SolidColorBrush(Colors.Black);
            pin.Location = new GeoCoordinate(App.ViewModel.SelectedEvent.EventLatitude, App.ViewModel.SelectedEvent.EventLongitue);
            pin.Content = App.ViewModel.SelectedEvent.EventTitle;
            EventMap.Children.Add(pin);
            EventMap.SetView(new GeoCoordinate(App.ViewModel.SelectedEvent.EventLatitude, App.ViewModel.SelectedEvent.EventLongitue, 200), 14);
        }
    }
}